package com.course.serviceImpl;

import java.io.FileNotFoundException;
import java.util.Vector;

import com.course.bean.AnnouncementTo;
import com.course.bean.CourseTo;
import com.course.daoI.CourseDAOI;
import com.course.daoImpl.CourseDaoImpl;
import com.course.exception.ConnectionException;
import com.course.exception.DataNotFoundException;
import com.course.exception.LoginException;
import com.course.serviceI.CourseServiceI;

public class CourseServiceImpl implements CourseServiceI{
	
	
	
	
	CourseDAOI cdao=new CourseDaoImpl();
	
	boolean flag=false;
	
	Vector<CourseTo> vcto=null;
	Vector<AnnouncementTo> vato=null;

	public boolean insertCourse(CourseTo cb)throws LoginException,ConnectionException{
		
		flag=cdao.insertCourse(cb);
		if(flag==false)
		{
			
			throw new ConnectionException();
			}
       else if (cb.getCname()==null || cb.getCname().equals("")) {
			
			
			throw new LoginException();
			
		}
		return flag;
		}
	
	public boolean deleteCourse(int courseid)throws LoginException,ConnectionException {
		
		flag= cdao.deleteCourse(courseid);
		if(flag==false)
		{
			
			throw new ConnectionException();
			}
		 else if (courseid==0) {
				
				
				throw new LoginException();
				
			}
			return flag;
		
	}
	public Vector<CourseTo> viewCourse()throws DataNotFoundException{
		
		vcto= cdao.viewCourse();
		
		
	 if (vcto.isEmpty()) {
			
			throw new DataNotFoundException();
			
		}
		return vcto;
		
		
		
		
	}
	public Vector<CourseTo> viewCourseAt(int cid)throws DataNotFoundException{
		
	   vcto= cdao.viewCourseAt(cid);
       
	   if (vcto.isEmpty()) {
			
			throw new DataNotFoundException();
			
		}
		return vcto;
		
		
	}
	public boolean updateCourse(CourseTo cb)throws LoginException,ConnectionException{
		
		flag= cdao.updateCourse(cb);
		
		if(flag==false)
		{
			
			throw new ConnectionException();
			}
       else if (cb.getCname()==null || cb.getCname().equals("")) {
			
			
			throw new LoginException();
			
		}
		return flag;
		
		
		
		
	}
	public boolean insertAnnouncement(AnnouncementTo ab)throws LoginException,ConnectionException{
		
		flag= cdao.insertAnnouncement(ab);
		if(flag==false)
		{
		  throw new ConnectionException();
			}
       else if (ab.getDescription()==null || ab.getDescription().equals("")) {
			throw new LoginException();
			}
		return flag;
		}
	public Vector<AnnouncementTo> viewAnnouncement(int cid)throws DataNotFoundException{
		
	       vato= cdao.viewAllAnnouncement();
	   if (vato.isEmpty()) {
		throw new DataNotFoundException();
		}
	      return vato;
	      }
	public Vector<AnnouncementTo> viewAllAnnouncement()throws DataNotFoundException{
		
		vato= cdao.viewAllAnnouncement();
		 if (vato.isEmpty()) {
				throw new DataNotFoundException();
				}
			   return vato;
			   }
	public boolean insertMaterial(CourseTo cb)throws FileNotFoundException, ConnectionException, LoginException{
		
		flag= cdao.insertMaterial(cb);
		
		if(flag==false)
		{
			throw new ConnectionException();
			}
       else if(cb.getMaterial()==null || cb.getMaterial().equals("")) {
			throw new LoginException();
			}
		return flag;
	}
	public Vector<CourseTo> viewMaterial(String path,int cid)throws DataNotFoundException{
		
		vcto= cdao.viewMaterial(path, cid);
		
		if (vcto.isEmpty()) {
			
			throw new DataNotFoundException();
			
		   }
		      return vcto;
		
	}
	public Vector<CourseTo> getFaculty(int cid)throws DataNotFoundException{
		
		vcto= cdao.getFaculty(cid);
		
     if (vcto.isEmpty()) {
			
			throw new DataNotFoundException();
			
		   }
		      return vcto;
		
		
		
	}
	public Vector<CourseTo> getStudent(int cid)throws DataNotFoundException{
		
		vcto= cdao.getStudent(cid);
		
      if (vcto.isEmpty()) {
			
			throw new DataNotFoundException();
			
		   }
		      return vcto;
	}
	
	
}
